<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>个人中心</title>
    <%- include common %>
</head>
<body>
    <%- include('head',{title:'mine',username:username })%>
    <div class="container">
        <h2 class="text-success" >个人中心</h2>
        <div class="row">
            <div class="col-md-4 ">
                <p>用户名: <%- result.username %></p>
                <p>手机号码: <%- result.mobile %></p>
                <p>
                    <button class="btn btn-primary" data-toggle="modal" data-target="#updatepass">修改密码</button>
                </p>
            </div>
        </div>
    </div>

    <div class="modal fade"  tabindex="-1" role="dialog" id="updatepass">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改密码</h4>
            </div>
            <div class="modal-body">
                    <div class="form-group">
                        <label for="password">旧密码</label>
                        <input type="password" name="oldpassword"   class="form-control" id="oldpassword" placeholder="Old Password">
                    </div>
                    <div class="form-group">
                        <label for="password"> 新密码</label>
                        <input type="password"  name="newpassword" class="form-control" id="newpassword" placeholder="New Password">
                    </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary"   onclick="todoUpdatePass()"   >确定修改</button>
            </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <%- include foot %>

    <script>
        function todoUpdatePass(){
            $.ajax({
                url:'/changepass',
                type:'POST',
                data:{
                    oldpassword:$('#oldpassword').val(),
                    newpassword:$('#newpassword').val(),
                },
                success:res=>{
                    $('#updatepass').modal('toggle');
                    setTimeout(()=>{
                        alert(res.msg);
                    })
                    if(res.type || res.code==3000){
                        location.href = '/login';
                    }
                }
            })
        }

    </script>
</body>
</html>